package com.airy.apprepairequipment.common.util;

import net.sf.json.JSONObject;

public class JsonResult {
	private int resultCode;
	private String resultHint;
	private boolean successful;
	private Object resultValue;

	public JsonResult() {
		this.setResultCode(ResultCode.SUCCESS);
		this.setResultHint(ResultCode.SUCCESS.msg());
	}

	public JsonResult(Object resultValue) {
		this.setResultCode(ResultCode.SUCCESS);
		this.setResultHint(ResultCode.SUCCESS.msg());
		this.setResultValue(resultValue);
	}

	public JsonResult(ResultCode code) {
		this.setResultCode(code);
		this.setResultHint(code.msg());
	}

	public JsonResult(ResultCode code, String message) {
		this.setResultCode(code);
		this.setResultHint(message);
	}
	
	public JsonResult(ResultCode code, Object data) {
		this.setResultCode(code);
		this.setResultHint(code.msg());
		this.setResultValue(data);
	}

//	public JsonResult(ResultCode code, String message, Object data) {
//		this.setCode(code);
//		this.setMessage(message);
//		this.setData(data);
//	}


	public int getResultCode() {
		return resultCode;
	}

	public void setResultCode(ResultCode resultCode) {
		this.resultCode = resultCode.val();
	}

	public String getResultHint() {
		return resultHint;
	}

	public void setResultHint(String resultHint) {
		this.resultHint = resultHint;
	}

	public boolean isSuccessful() {
		return successful;
	}

	public void setSuccessful(boolean successful) {
		this.successful = successful;
	}

	public Object getResultValue() {
		return resultValue;
	}

	public void setResultValue(Object resultValue) {
		this.resultValue = resultValue;
	}

	public String toJsonString(){
		JSONObject json = JSONObject.fromObject(this);
		return json.toString();
	}
}
